import uuid
from django.db import models


class Users(models.Model):
    id = models.UUIDField(
        primary_key=True, default=uuid.uuid4, editable=False, verbose_name="ID"
    )
    username = models.CharField(max_length=255, verbose_name="用户名")
    email = models.EmailField(max_length=255, verbose_name="邮箱")
    password = models.CharField(max_length=255, verbose_name="密码")

    def __str__(self):
        return self.username

    class Meta:
        db_table = "users"
        verbose_name = "用户表"
        verbose_name_plural = verbose_name


class BuildInfo(models.Model):
    id = models.UUIDField(
        primary_key=True, default=uuid.uuid4, editable=False, verbose_name="ID"
    )
    build_name = models.CharField(max_length=255, verbose_name="构建名称")
    build_version = models.CharField(max_length=255, verbose_name="构建版本")
    build_time = models.DateTimeField(auto_now_add=True, verbose_name="构建时间")
    build_url = models.URLField(max_length=255, verbose_name="构建地址")
    build_status = models.BooleanField(verbose_name="构建状态")
    reserved_field0 = models.CharField(
        max_length=255, null=True, blank=True, verbose_name="预留字段0"
    )
    reserved_field1 = models.CharField(
        max_length=255, null=True, blank=True, verbose_name="预留字段1"
    )
    reserved_field2 = models.CharField(
        max_length=255, null=True, blank=True, verbose_name="预留字段2"
    )

    def __str__(self):
        return self.build_name

    class Meta:
        db_table = "build_info"
        verbose_name = "构建信息表"
        verbose_name_plural = verbose_name


# Create your models here.
class AITestCase(models.Model):
    id = models.UUIDField(
        primary_key=True, default=uuid.uuid4, editable=False, verbose_name="ID"
    )
    test_summary = models.CharField(
        max_length=255, null=True, blank=True, verbose_name="测试简述"
    )
    test_requirements = models.CharField(
        max_length=1000, null=True, blank=True, verbose_name="测试需求"
    )
    detail = models.CharField(
        max_length=1000, null=True, blank=True, verbose_name="详情"
    )
    remark = models.TextField(
        max_length=1000, null=True, blank=True, verbose_name="备注"
    )
    build_info = models.ManyToManyField(
        BuildInfo, related_name="build_info", blank=True, verbose_name="集成信息"
    )
    user = models.ForeignKey(
        Users,
        db_constraint=False,
        verbose_name="人员",
        on_delete=models.SET_NULL,
        null=True,
        blank=True,
    )
    reserved_field0 = models.CharField(
        max_length=255, null=True, blank=True, verbose_name="预留字段0"
    )
    reserved_field1 = models.CharField(
        max_length=255, null=True, blank=True, verbose_name="预留字段1"
    )
    reserved_field2 = models.CharField(
        max_length=255, null=True, blank=True, verbose_name="预留字段2"
    )

    def __str__(self):
        return self.test_summary

    class Meta:
        db_table = "ai_test_case"
        verbose_name = "AI测试用例表"
        verbose_name_plural = verbose_name


class AITestDetail(models.Model):
    id = models.UUIDField(
        primary_key=True, default=uuid.uuid4, editable=False, verbose_name="ID"
    )
    index = models.IntegerField(verbose_name="序号")
    test_step = models.CharField(
        max_length=500, verbose_name="测试步骤", null=False, blank=True
    )
    expected_result = models.CharField(
        max_length=500, verbose_name="期望结果", null=True, blank=True
    )
    modify_history = models.JSONField(null=True, blank=True, verbose_name="修改历史")
    detail = models.CharField(
        max_length=1000, null=True, blank=True, verbose_name="详情"
    )
    remark = models.TextField(
        max_length=1000, null=True, blank=True, verbose_name="备注"
    )
    ai_test_case = models.ForeignKey(
        AITestCase,
        on_delete=models.SET_NULL,
        null=True,
        related_name="ai_test_detail",
        verbose_name="测试用例表外键",
    )
    reserved_field0 = models.CharField(
        max_length=255, null=True, blank=True, verbose_name="预留字段0"
    )
    reserved_field1 = models.CharField(
        max_length=255, null=True, blank=True, verbose_name="预留字段1"
    )
    reserved_field2 = models.CharField(
        max_length=255, null=True, blank=True, verbose_name="预留字段2"
    )

    def __str__(self):
        return self.test_step

    class Meta:
        db_table = "ai_test_detail"
        verbose_name = "AI测试步骤表"
        verbose_name_plural = verbose_name
